package com.zlsy.thread.cas;

/**
 * @author zhouliang
 * @date 2020/8/20 20:46
 * 模拟cas
 */
public class SimulateCAS {

    private volatile int value;

    public synchronized int compareAndSwap(int expectValue, int newValue) {
        int oldValue = value;
        if (oldValue == expectValue) {
            value = newValue;
        }
        return oldValue;
    }
}
